package com.ruoyi.project.jiaqin.supplycollect.service.impl;

import java.util.List;
import java.util.UUID;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.project.jiaqin.supply.domain.Supply;
import com.ruoyi.project.jiaqin.supply.mapper.SupplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.jiaqin.supplycollect.mapper.JiaqinSupplyCollectMapper;
import com.ruoyi.project.jiaqin.supplycollect.domain.JiaqinSupplyCollect;
import com.ruoyi.project.jiaqin.supplycollect.service.IJiaqinSupplyCollectService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 供应收藏Service业务层处理
 *
 * @author admin
 * @date 2021-01-05
 */
@Service
public class JiaqinSupplyCollectServiceImpl implements IJiaqinSupplyCollectService
{
    @Autowired
    private JiaqinSupplyCollectMapper jiaqinSupplyCollectMapper;
    @Autowired
    private SupplyMapper supplyMapper;
    /**
     * 查询供应收藏
     *
     * @param id 供应收藏ID
     * @return 供应收藏
     */
    @Override
    public JiaqinSupplyCollect selectJiaqinSupplyCollectById(String id)
    {
        return jiaqinSupplyCollectMapper.selectJiaqinSupplyCollectById(id);
    }

    @Override
    public JiaqinSupplyCollect selectJiaqinSupplyCollectByMemberIdAndToSupplyId(String memberId, String toSupplyId) {
        return jiaqinSupplyCollectMapper.selectJiaqinSupplyCollectByMemberIdAndToSupplyId(memberId,toSupplyId);
    }

    @Override
    public PageInfo<JiaqinSupplyCollect> selectJiaqinSupplyCollectByMemberId(Integer pageNum ,Integer pageSize,String memberId) {
        PageHelper.startPage(pageNum,pageSize);
        List<JiaqinSupplyCollect> list = jiaqinSupplyCollectMapper.selectJiaqinSupplyCollectByMemberId(memberId);
        if(list != null && list.size() !=0){
            for (JiaqinSupplyCollect j: list) {
                Supply supply = supplyMapper.selectSupplyById(j.getSupplyId());
                j.setSupply(supply);
            }
        }
        PageInfo<JiaqinSupplyCollect> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 查询供应收藏列表
     *
     * @param jiaqinSupplyCollect 供应收藏
     * @return 供应收藏
     */
    @Override
    public List<JiaqinSupplyCollect> selectJiaqinSupplyCollectList(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        return jiaqinSupplyCollectMapper.selectJiaqinSupplyCollectList(jiaqinSupplyCollect);
    }

    /**
     * 新增供应收藏
     *
     * @param jiaqinSupplyCollect 供应收藏
     * @return 结果
     */
    @Override
    public int insertJiaqinSupplyCollect(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        jiaqinSupplyCollect.setId(UUID.randomUUID().toString().replace("-",""));
        return jiaqinSupplyCollectMapper.insertJiaqinSupplyCollect(jiaqinSupplyCollect);
    }

    /**
     * 修改供应收藏
     *
     * @param jiaqinSupplyCollect 供应收藏
     * @return 结果
     */
    @Override
    public int updateJiaqinSupplyCollect(JiaqinSupplyCollect jiaqinSupplyCollect)
    {
        return jiaqinSupplyCollectMapper.updateJiaqinSupplyCollect(jiaqinSupplyCollect);
    }

    /**
     * 删除供应收藏对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteJiaqinSupplyCollectByIds(String ids)
    {
        return jiaqinSupplyCollectMapper.deleteJiaqinSupplyCollectByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除供应收藏信息
     *
     * @param id 供应收藏ID
     * @return 结果
     */
    @Override
    public int deleteJiaqinSupplyCollectById(String id)
    {
        return jiaqinSupplyCollectMapper.deleteJiaqinSupplyCollectById(id);
    }
}
